/*     */ package com.zimbra.cs.service.mail;
/*     */ 
/*     */ import com.zimbra.common.service.ServiceException;
/*     */ import com.zimbra.common.soap.Element;
/*     */ import com.zimbra.common.soap.MailConstants;
/*     */ import com.zimbra.common.util.Pair;
/*     */ import com.zimbra.cs.mailbox.Contact;
/*     */ import com.zimbra.cs.mailbox.Contact.Attachment;
/*     */ import com.zimbra.cs.mailbox.MailItem.Type;
/*     */ import com.zimbra.cs.mailbox.Mailbox;
/*     */ import com.zimbra.cs.mailbox.OperationContext;
/*     */ import com.zimbra.cs.mailbox.util.TagUtil;
/*     */ import com.zimbra.cs.mime.ParsedContact;
/*     */ import com.zimbra.cs.service.util.ItemId;
/*     */ import com.zimbra.cs.service.util.ItemIdFormatter;
/*     */ import com.zimbra.soap.ZimbraSoapContext;
/*     */ import java.util.HashMap;
/*     */ import java.util.List;
/*     */ import java.util.Map;
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ public class ModifyContact
/*     */   extends MailDocumentHandler
/*     */ {
/*  47 */   private static final String[] TARGET_FOLDER_PATH = { "cn", "id" };
/*     */   
/*  49 */   protected String[] getProxiedIdPath(Element request) { return TARGET_FOLDER_PATH; }
/*     */   
/*  51 */   protected boolean checkMountpointProxy(Element request) { return false; }
/*     */   
/*     */   public Element handle(Element request, Map<String, Object> context) throws ServiceException
/*     */   {
/*  55 */     ZimbraSoapContext zsc = getZimbraSoapContext(context);
/*  56 */     Mailbox mbox = getRequestedMailbox(zsc);
/*  57 */     OperationContext octxt = getOperationContext(zsc, context);
/*  58 */     ItemIdFormatter ifmt = new ItemIdFormatter(zsc);
/*     */     
/*  60 */     boolean replace = request.getAttributeBool("replace", false);
/*  61 */     boolean verbose = request.getAttributeBool("verbose", true);
/*     */     
/*  63 */     Element cn = request.getElement("cn");
/*  64 */     ItemId iid = new ItemId(cn.getAttribute("id"), zsc);
/*  65 */     String tagsAttr = cn.getAttribute("tn", null);
/*  66 */     String[] tags = tagsAttr == null ? null : TagUtil.decodeTags(tagsAttr);
/*     */     
/*  68 */     Contact contact = mbox.getContactById(octxt, iid.getId());
/*     */     ParsedContact pc;
/*     */     ParsedContact pc;
/*  71 */     if (replace) {
/*  72 */       Pair<Map<String, Object>, List<Contact.Attachment>> cdata = CreateContact.parseContact(cn, zsc, octxt, contact);
/*  73 */       pc = new ParsedContact((Map)cdata.getFirst(), (List)cdata.getSecond());
/*     */     } else {
/*  75 */       pc = CreateContact.parseContactMergeMode(cn, zsc, octxt, contact);
/*     */     }
/*     */     
/*  78 */     if (CreateContact.needToMigrateDlist(zsc)) {
/*  79 */       CreateContact.migrateFromDlist(pc);
/*     */     }
/*     */     
/*  82 */     mbox.modifyContact(octxt, iid.getId(), pc);
/*  83 */     if (tags != null) {
/*  84 */       mbox.setTags(octxt, iid.getId(), MailItem.Type.CONTACT, Integer.MIN_VALUE, tags);
/*     */     }
/*     */     
/*  87 */     Contact con = mbox.getContactById(octxt, iid.getId());
/*  88 */     Element response = zsc.createElement(MailConstants.MODIFY_CONTACT_RESPONSE);
/*  89 */     if (con != null) {
/*  90 */       if (verbose) {
/*  91 */         ToXML.encodeContact(response, ifmt, octxt, con, true, null);
/*     */       } else
/*  93 */         response.addElement("cn").addAttribute("id", con.getId());
/*     */     }
/*  95 */     return response;
/*     */   }
/*     */   
/*     */   static Map<String, String> parseFields(List<Element> elist) throws ServiceException {
/*  99 */     if ((elist == null) || (elist.isEmpty())) {
/* 100 */       return null;
/*     */     }
/* 102 */     HashMap<String, String> attrs = new HashMap();
/* 103 */     for (Element e : elist) {
/* 104 */       String name = e.getAttribute("n");
/* 105 */       attrs.put(name, e.getText());
/*     */     }
/* 107 */     return attrs;
/*     */   }
/*     */ }


/* Location:              /home/mint/zimbrastore.jar!/com/zimbra/cs/service/mail/ModifyContact.class
 * Java compiler version: 7 (51.0)
 * JD-Core Version:       0.7.1
 */